package com.hospital.hospitalworkservice.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hospital.common.vo.ResultEntity;
import com.hospital.hospitalworkservice.entity.Vipperson;
import com.hospital.hospitalworkservice.service.IVippersonService;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayOutputStream;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author dwl
 * @since 2020-10-21
 */
@RestController
@RequestMapping("/vipperson")
public class VippersonController {

    @Autowired
    IVippersonService iVippersonService;

    @RequestMapping("/list")
    public ResultEntity list(Page page, Vipperson vo){
        IPage<Vipperson> list = iVippersonService.selectPageVo(page, vo);
        return ResultEntity.ok("200","列表访问成功",list);
    }


    @RequestMapping("/update")
    public ResultEntity update(@RequestBody Vipperson vipperson){
        boolean save = iVippersonService.saveOrUpdate(vipperson);
        return ResultEntity.ok("200","修改成功",save);
    }



    @RequestMapping("/download")
    public ResponseEntity<byte[]> downLoadGoodsExcel() throws  IllegalAccessException, Exception, ClassNotFoundException {
        XSSFWorkbook xssfSheets = iVippersonService.daochu();
        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        xssfSheets.write(byteArrayOutputStream);
        HttpHeaders httpHeaders =  new HttpHeaders();
        httpHeaders.setContentDispositionFormData("attachment", new String("会员表.xls".getBytes("UTF-8"), "ISO-8859-1"));
        httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity(byteArrayOutputStream.toByteArray(),httpHeaders, HttpStatus.CREATED);
    }
}
